package com.vm.utils;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.HashMap;
import java.util.UUID;

import com.vm.commons.CurrentUser;
import com.vm.commons.VMConst;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.drawable.BitmapDrawable;
import android.util.Log;

public class UploadUtil {
	private static final String TAG = "uploadFile";
	private static final int TIME_OUT = 10 * 1000; // 超时时间
	private static final String CHARSET = "utf-8"; // 设置编码

	public static String uploadFile(File imageFile,String fileName) {

		try {
			String requestUrl = VMConst.REQUEST_URL + "upload_image";
			// 请求普通信息
			HashMap<String, String> params = new HashMap<String, String>();
			// params.put("filename", "张三");
			params.put("name", "张三");
			params.put("fileName", fileName);
			params.put("userId", CurrentUser.USERID);
			// 上传文件
			FormFile formfile = new FormFile(imageFile.getName(), imageFile,
					"image", "application/octet-stream");

			SocketHttpRequester.post(requestUrl, params, formfile);

		} catch (Exception e) {
			Log.i(TAG, "upload error");
			e.printStackTrace();
		}

		Log.i(TAG, "upload end");
		return "OK";
	}
}